package com.loie.xcx.config;

import com.loie.xcx.interceptor.LoginInterceptor;
import com.loie.xcx.model.bo.CurrentUserHandlerMethodArgResolver;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.List;

/**
 * @author zhl
 */
@Configuration
public class WebConfigure implements WebMvcConfigurer {

    private final LoginInterceptor loginInterceptor;
    private final DgMvcProperties wxMVCProperties;

    public WebConfigure(LoginInterceptor loginInterceptor, DgMvcProperties wxMvcProperties) {
        this.loginInterceptor = loginInterceptor;
        this.wxMVCProperties = wxMvcProperties;
    }

    @Override
    public void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
        //注册@CurrentUser注解的实现类
        argumentResolvers.add(new CurrentUserHandlerMethodArgResolver());
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        InterceptorRegistration ir = registry.addInterceptor(loginInterceptor);
        ir.addPathPatterns("/**");
        ir.excludePathPatterns(wxMVCProperties.getContextInterceptorExcludePathPatterns());
    }
}